#include "tools.cpp"

class Solution {
public:
    bool isSubStructure(TreeNode* root1, TreeNode* root2) {
        if (root2 == nullptr or root1 == nullptr) return false;
        return helper(root1, root2) or isSubStructure(root1->left, root2) or isSubStructure(root1->right, root2);
    }

    bool helper(TreeNode* root1, TreeNode* root2){
        if (root2 == nullptr) return true;
        if (root1 == nullptr) return false;
        if (root1->val == root2->val) return helper(root1->left, root2->left) and helper(root1->right, root2->right);
        return false;
    }
};

int main(){
    auto root1 = new TreeNode(std::vector<int>{2, 3, 2, 1});
    auto root2 = new TreeNode(std::vector<int>{1});
    Solution s;
    std::cout << s.isSubStructure(root1, root2) << std::endl;
}
